package com.cmy.framework_network.commoninterceptor

import com.cmy.framework_network.base.INetworkRequiredInfo
import okhttp3.Interceptor
import okhttp3.Response

/**
 * 基础请求头，实现请求时添加请求头
 */
class CommonRequestInterceptor( requiredInfo:INetworkRequiredInfo?) : Interceptor {

    private val mRequiredInfo: INetworkRequiredInfo? = requiredInfo

    override fun intercept(chain: Interceptor.Chain): Response {
        val builder = chain.request().newBuilder()
        builder.addHeader("os", "android")
        mRequiredInfo?.let {
            builder.addHeader("appVersion", it.getAppVersionCode())
        }

        return chain.proceed(builder.build())
    }
}